/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.business.security.boundary;

import it.polimi.registration.business.security.entity.Location;
import it.polimi.registration.business.security.entity.MyForecast;
import java.util.Date;
import javax.ejb.EJB;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 *
 * @author Luca
 */
@RunWith(Arquillian.class)
public class ForecastManagerIT {
    @PersistenceContext
    EntityManager em;
    
    @EJB
    ForecastManager fm;
    
    @Deployment
    public static WebArchive createArchiveAndDeploy() {
        return ShrinkWrap.create(WebArchive.class)
                .addClass(ForecastManager.class)
                .addPackage(MyForecast.class.getPackage())
                .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
    }
    
    @Test
    public void newEventsShouldBeValid() {
        MyForecast newForecast = new MyForecast();
        newForecast.setDate(new Date());
        newForecast.setDescription("rain");
        newForecast.setId(Long.MIN_VALUE);
        newForecast.setLocation(new Location());
        fm.save(newForecast);
        MyForecast mf = em.find(MyForecast.class, newForecast.getId());
        assertEquals(mf.getId(),newForecast.getId());
    }
}
